package dao

import (
	"ruoyi-hello/app/sys/model"
	"ruoyi-hello/config"
	"ruoyi-hello/utils/error"
)

var TableSysUserTable = "sys_user"

func GetUserByLoginName(loginName string) (model.SysUser, error.BusstionError) {
	var sysUser model.SysUser
	err := config.MysqlConn.Primary.Table(TableSysUserTable).Where(" user_name = ?", loginName).Find(&sysUser)
	if err.Error != nil {
		return model.SysUser{}, error.BusstionError{Code: error.SelectException.Code, Msg: "用户信息不存在", Err: err.Error}
	}
	return sysUser, error.BusstionError{Code: error.Ok.Code}
}

func GetUserById(userId int) model.SysUser {
	var sysUser model.SysUser
	err := config.MysqlConn.Primary.Table(TableSysUserTable).Where(" user_id = ?", userId).Find(&sysUser)
	if err.Error != nil {
		return model.SysUser{UserId: 0}
	}
	return sysUser
}
